<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of model_admins
 *
 * @author ChristianNotebook
 */


class Model_admins extends CI_Model {
    function Model_admins()
    {
        parent::__construct();
    }

    // verifys a user with username and password
    function verify_user($u, $pw) {
        $this->db->select('id', 'username');
        $this->db->where('username', $u);
        $this->db->where('password', $pw);
        $this->db->where('status', 'active');
        $this->db->limit(1);
        $Q = $this->db->get('admins');
        if ($Q->num_rows() > 0)
        {
            $row = $Q->row_array();
            $data = array(
                'userid' => $row['id'],
                'username' => 'username'
                );
            $this->session->set_userdata($data);
        }
        else
        {
            $this->session->set_flashdata('error', 'Sorry, your username and password is incorrect!');
        }
    }

    // gets all users from the db and returns them in an array
    function getAllUsers() {
        $data = array();
        $this->db->order_by('last_name','asc');
        $Q = $this->db->get('user');

        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
        $Q->free_result();
        return $data;
    }

    // updates a specific user by userid 
    function update_user(){
      $data = array(
          'username' => $_POST['username'],
          'first_name' => $_POST['first_name'],
          'last_name' => $_POST['last_name'],
          'birthday' => $_POST['birthday'],
          'email' => $_POST['email'],
          'password' => md5($_POST['password']),
          'bio' => $_POST['bio'],
          'status' => $_POST['status']
          );
	  $this->db->where('id',$_POST['id']);
	  $this->db->update('user',$data);

	}

}
?>
